package com.wuxiaoqin.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wuxiaoqin.admin.entity.AddCommodity;
import com.wuxiaoqin.admin.entity.Commodity;
import com.wuxiaoqin.admin.entity.Goodsimg;
import com.wuxiaoqin.admin.entity.Goodsstock;
import com.wuxiaoqin.admin.entity.goodParam.GoodsAdd;
import com.wuxiaoqin.admin.entity.goodParam.GoodsAll;
import com.wuxiaoqin.admin.entity.goodParam.GoodsImgModify;
import com.wuxiaoqin.admin.entity.goodParam.GoodsSales;
import com.wuxiaoqin.admin.service.ICommodityService;
import com.wuxiaoqin.uitls.respObj.RespBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-11-02
 */
@RestController
public class CommodityController {

    @Autowired
    private ICommodityService commodityService;


    @ApiOperation("查询分类")
    @GetMapping("/selectClass")
    public RespBean selectClass(){
        return commodityService.selectClass();
    }


    @ApiOperation("添加商品")
    @PostMapping("/addGoodsTest")
    public RespBean addGoodsTest(GoodsAdd goodsAdd,
                             MultipartFile file) throws IOException {
      return   commodityService.goodsAdd(file,goodsAdd);
    }



    @ApiOperation("查询所有商品")
    @GetMapping("/getGoods")
    public Page<GoodsAll> getGoods(@RequestParam("pn") Integer pn, @RequestParam("size") Integer size){
        return   commodityService.getGoods(pn,size);
    }


    @ApiOperation("查询单个商品")
    @GetMapping("/getGoodsById")
    public Commodity getGoodsById(@RequestParam("id") Integer id){
        return   commodityService.getGoodsById(id);
    }

    @ApiOperation("删除商品")
    @GetMapping("/deleteGoodById")
    public RespBean deleteGoodById(@RequestParam("id") Integer id){
        return   commodityService.deleteGoodById(id);
    }


    @ApiOperation("查询单个商品的库存")
    @GetMapping("/getGoodsStockById")
    public Goodsstock getGoodsStockById(@RequestParam("id") Integer id){
        return   commodityService.getGoodsStockById(id);
    }

    @ApiOperation("查询商品的附加图片")
    @GetMapping("/getGoodsImg")
    public Goodsimg getGoodsImg(@RequestParam("id") Integer id){
        return   commodityService.getGoodsImg(id);
    }

    @ApiOperation("修改商品附加图片(存在则更改不存在就添加)")
    @PostMapping("/addGoodsImg")
    public RespBean modifyGoodsImg(Integer id,
                                   MultipartFile file1,
                                   MultipartFile file2,
                                   MultipartFile file3,
                                   MultipartFile file4) throws IOException {
        System.out.println("123123");
        GoodsImgModify goodsImgModify = new GoodsImgModify();
        goodsImgModify.setFileImg1(file1);
        goodsImgModify.setFileImg2(file2);
        goodsImgModify.setFileImg3(file3);
        goodsImgModify.setFileImg4(file4);
        return   commodityService.modifyGoodsImg(id,goodsImgModify);
    }
    @ApiOperation("删除商品附加图片")
    @DeleteMapping("/delGoodsImg")
    public RespBean delGoodsImg(@RequestParam("id") Integer id) {
        return   commodityService.delGoodsImg(id);
    }


    @ApiOperation("销量统计数据")
    @GetMapping("/salesVolume")
    public Page<GoodsSales> salesVolume(
            @RequestParam("pn") Integer pn, @RequestParam("size") Integer size
    ) {
        return   commodityService.salesVolume(pn,size);
    }
}
